﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Reports.Schedule
{
    public class Report1:DependencyObject
    {
        public static DependencyProperty StartDateProperty = DependencyProperty.Register("StartDate", typeof(DateTime), typeof(Report1));
        public DateTime StartDate
        {
            get { return (DateTime)GetValue(StartDateProperty); }
            set
            {
                SetValue(StartDateProperty, value);
            }
        }
        public static DependencyProperty EndDateProperty = DependencyProperty.Register("EndDate", typeof(DateTime), typeof(Report1));
        public DateTime EndDate
        {
            get { return (DateTime)GetValue(EndDateProperty); }
            set
            {
                SetValue(EndDateProperty, value);
            }
        }
        public Report1()
        {
            EndDate = DateTime.Now;
            if (DateTime.Now.Month > 1)
                StartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month - 1, DateTime.Now.Day);
            else StartDate = new DateTime(DateTime.Now.Year - 1, 12, DateTime.Now.Day);
        }
        public CrystalReport1 Load(TinyCinema.Bussiness.Login.Employee LoginInfo)
        {
            string sql = "select TABLE1.Thu,TABLE1.GioBatDau,TABLE1.GioKetThuc,"
            + " CASE WHEN TABLE2.SOVE is null then 0 else TABLE2.SOVE end as SoVe,"
            + " CASE WHEN TABLE2.DoanhSo is null then 0 else TABLE2.DoanhSo end as DoanhSo"
            + " FROM (SELECT THU,GioBatDau,GioKetThuc FROM DONGIASUATCHIEU GROUP BY THU,GioBatDau,GioKetThuc) AS TABLE1"
            + " Left join (SELECT DONGIASUATCHIEU.Thu, DONGIASUATCHIEU.GioBatDau,DONGIASUATCHIEU.GioKetThuc, COUNT(VE.MaVe) AS SOVE,SUM(VE.Gia) as DoanhSo"
            + " FROM SUATCHIEU,VE,DONGIASUATCHIEU"
            + " WHERE SUATCHIEU.MaDG = DONGIASUATCHIEU.MaDG AND VE.MaSC=SUATCHIEU.MaSC"
            + " and SUATCHIEU.NgayChieu>='" + StartDate + "'"
            + " and SUATCHIEU.NgayChieu<='" + EndDate + "'"
            + " GROUP BY DONGIASUATCHIEU.Thu,DONGIASUATCHIEU.GioBatDau,DONGIASUATCHIEU.GioKetThuc)"
            + " AS TABLE2 on TABLE2.Thu=TABLE1.Thu and TABLE2.GioBatDau = TABLE1.GioBatDau and TABLE1.GioKetThuc = TABLE2.GioKetThuc";
            CrystalReport1 report = new CrystalReport1();
            report.SetDataSource(TinyCinema.Data.Execution.Excute(sql));
            report.SetParameterValue("StartDate", StartDate);
            report.SetParameterValue("EndDate", EndDate);
            report.SetParameterValue("EmployeeName", LoginInfo.Emp.Name);
            return report;
        }
       
    }
}
